<%@page import="weaver.conn.RecordSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
    try {
        // URL 参数
        Object awards_subname_id = request.getParameter("awardsSubnameId");         // 参与子奖项id(只允许查询一级）
        Object about  = request.getParameter("about");                              // 提名介绍（html格式保存）
        Object declaration  = request.getParameter("declaration");                  // 提名宣言
        Object poject_num  = request.getParameter("pojectNum");                     // 项目编号
        Object nominator_project_name  = request.getParameter("nominatorProjectName"); // 项目名称
        Object applicant_name  = request.getParameter("applicantName");             // 申请人名称
        Object applicant_dept_name  = request.getParameter("applicantDeptName");    // 申请人部门名称
        Object applicant_position  = request.getParameter("applicantPosition");     // 申请人职位
        Object nominator_name = request.getParameter("nominatorName");              // 被提名名称
        Object nominator_dept_name = request.getParameter("nominatorDeptName");     // 被提名部门名称
        Object nominator_position = request.getParameter("nominatorPosition");      // 被提名职位
        Object nominator_photo = request.getParameter("nominatorPhoto");            // 被提名照片（参与人头像）
        Object nominator_type = request.getParameter("nominatorType");              // 被提名类型：1 个人 2 团队
        Object nominator_status = request.getParameter("nominatorStatus");          // 被提名状态：0 待提名 1 提名中 -1 提名驳回
        Object complete = request.getParameter("complete");                         // 做了什么
        Object influence = request.getParameter("influence");                       // 成就/影响
        Object project_goal = request.getParameter("projectGoal");                  // 方案目标
        Object is_economic = request.getParameter("isEconomic");                    // 是否有经济效益：0 没有 1 有
        Object save_money = request.getParameter("saveMoney");                      // 节约金额
        Object tuandui = request.getParameter("tuandui");                           // 团队成员名称
        Object poject_start_time = request.getParameter("pojectStartTime");         // 团队类型：成员信息 JSON对象
        Object poject_end_time = request.getParameter("pojectEndTime");         // 团队类型：成员信息 JSON对象
        String member_names = "";
        // 获取到参与人的名字
        if (nominator_type.equals("1")){
            member_names = nominator_name.toString();
        }else{
            member_names = tuandui.toString();
        }

        // 插入数据
        // 查询一级奖项
        String sql = "select awards_id from vote_awards_subname where id = "+awards_subname_id;
        RecordSet set  = new RecordSet();
	  	set.executeSql(sql);
        int awards_id = 0;
        while(set.next()){
            awards_id = set.getInt("awards_id");
        }

        sql = "INSERT INTO vote_awards_participator(" +
                "awards_id, " +
                (awards_subname_id==null?"":"awards_subname_id, ") +
                ("member_names, ") +
                (about!=null&&!about.equals("")?"about, ":"") +
                (declaration!=null&&!declaration.equals("")?"declaration, ":"") +
                (nominator_project_name!=null&&!nominator_project_name.equals("")?"nominator_project_name, ":"") +
                (poject_num!=null&&!poject_num.equals("")?"poject_num, ":"") +
                (applicant_name!=null&&!applicant_name.equals("")?"applicant_name, ":"") +
                (applicant_dept_name!=null&&!applicant_dept_name.equals("")?"applicant_dept_name, ":"") +
                (applicant_position!=null&&!applicant_position.equals("")?"applicant_position, ":"") +
                (nominator_name!=null&&!nominator_name.equals("")?"nominator_name, ":"") +
                (nominator_dept_name!=null&&!nominator_dept_name.equals("")?"nominator_dept_name, ":"") +
                (nominator_position!=null&&!nominator_position.equals("")?"nominator_position, ":"") +
                (nominator_photo!=null&&!nominator_photo.equals("")?"nominator_photo, ":"") +
                (nominator_type!=null&&!nominator_type.equals("")?"nominator_type, ":"") +
                (nominator_status!=null&&!nominator_status.equals("")?"nominator_status, ":"") +
                (complete!=null&&!complete.equals("")?"complete, ":"") +
                (influence!=null&&!influence.equals("")?"influence, ":"") +
                (is_economic!=null&&!is_economic.equals("")?"is_economic, ":"") +
                (save_money!=null&&!save_money.equals("")?"save_money, ":"") +
                (project_goal!=null&&!project_goal.equals("")?"project_goal, ":"") +
                (poject_start_time!=null&&!poject_start_time.equals("")?"poject_start_time, ":"") +
                (poject_end_time!=null&&!poject_end_time.equals("")?"poject_end_time, ":"") +
                "create_time) " +
                "values(" +
                awards_id+", " +
                (awards_subname_id==null?"":Integer.parseInt(awards_subname_id.toString())+", ") +
                ("N'"+member_names+"', ") +
                (about==null||about.equals("")?"":"N'"+about.toString()+"', ") +
                (declaration==null||declaration.equals("")?"":"N'"+declaration.toString()+"', ") +
                (nominator_project_name==null||nominator_project_name.equals("")?"":"N'"+nominator_project_name.toString()+"', ") +
                (poject_num==null||poject_num.equals("")?"":"N'"+poject_num.toString()+"', ") +
                (applicant_name==null||applicant_name.equals("")?"":"N'"+applicant_name.toString()+"', ") +
                (applicant_dept_name==null||applicant_dept_name.equals("")?"":"N'"+applicant_dept_name.toString()+"',") +
                (applicant_position==null||applicant_position.equals("")?"":"N'"+applicant_position.toString()+"',") +
                (nominator_name==null||nominator_name.equals("")?"":"N'"+nominator_name.toString()+"', ") +
                (nominator_dept_name==null||nominator_dept_name.equals("")?"":"N'"+nominator_dept_name.toString()+"',") +
                (nominator_position==null||nominator_position.equals("")?"":"N'"+nominator_position.toString()+"', ") +
                (nominator_photo==null||nominator_photo.equals("")?"":"N'"+nominator_photo.toString()+"', ") +
                (nominator_type==null||nominator_type.equals("")?"":nominator_type.toString()+", ") +
                (nominator_status==null||nominator_status.equals("")?"":Integer.parseInt(nominator_status.toString())+", ") +
                (complete==null||complete.equals("")?"":"N'"+complete.toString()+"', ") +
                (influence==null||influence.equals("")?"":"N'"+influence.toString()+"', ") +
                (is_economic==null||is_economic.equals("")?"":is_economic+", ") +
                (save_money==null||save_money.equals("")?"": save_money+", ") +
                (project_goal==null||project_goal.equals("")?"":"N'"+project_goal.toString()+"', ") +
                (poject_start_time==null||poject_start_time.equals("")?"":"N'"+poject_start_time.toString()+"', ") +
                (poject_end_time==null||poject_end_time.equals("")?"":"N'"+poject_end_time.toString()+"', ") +
                "GETDATE())";
        RecordSet set1  = new RecordSet();
	  	set1.executeSql(sql);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        if (printWriter != null)  printWriter.close();
    }
%>
